package com.woniu.p2p.factory;

import com.woniu.p2p.mapper.LimitVoMapper;
import com.woniu.p2p.vo.LimitVo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author 86152
 * @create 2020/8/14
 * @since 1.0.0
 */
public class FilterChainDefinitionMapBuilder {
    @Autowired
    LimitVoMapper limitVoMapper;

    public LinkedHashMap<String,String> filterChainDefinitionMapBuilder(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        List<LimitVo> limitVos = limitVoMapper.selectAll();

        for(LimitVo limitVo:limitVos){
            String action = limitVo.getAction();
            String role = limitVo.getRole();

            role="roles["+role;
            if(map.containsKey(action)){
                role+=","+map.get(action).substring(6);
            }else{
                role+="]";
            }
            map.put(action,role);
        }
        map.put("/css/**","anon");
        map.put("/fonts/**","anon");
        map.put("/i/**","anon");
        map.put("/img/**","anon");
        map.put("/js/**","anon");
        map.put("/admin/login","anon");
        map.put("/invest/**","anon");
        map.put("/details/**","anon");
        map.put("/moneyManage/**","anon");
        map.put("/myborrowHistory/**","anon");
        map.put("/myrepay/**","anon");
        map.put("/charge/**","anon");
        map.put("/coupon/**","anon");
        map.put("/index/**","anon");
        map.put("/message/**","anon");
        map.put("/userbank/**","anon");
        map.put("/depositsHistory/**","anon");
        map.put("/mymoney/**","anon");
        map.put("/new/**","anon");
        map.put("/score/**","anon");
        map.put("/show/**","anon");
        map.put("/user/**","anon");
        map.put("/sms/**","anon");
        map.put("/borrow/**","anon");
        map.put("/userHomePageController/**","anon");
        map.put("/index","authc");
        map.put("/**","authc");
        System.out.println(map);
        return map;
    }
}
